home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Freeware / Adobe Air 1.5 / AdobeAIRInstaller.exe / setup.swf / scripts / components / LocalizedText.as < prev    next >
Encoding:
Text File  |  2008-10-29  |  5.1 KB  |  183 lines

  1. package components
  2. {
  3.    import flash.text.Font;
  4.    import mx.controls.Text;
  5.    import mx.events.PropertyChangeEvent;
  6.    import mx.styles.StyleManager;
  7.    
  8.    public class LocalizedText extends Text
  9.    {
  10.       private static var fontArray:Array = Font.enumerateFonts(false);
  11.       
  12.       private var isFontRetrieved:Boolean = false;
  13.       
  14.       private var defaultAppFontFamily:String;
  15.       
  16.       private var _resourceName:String;
  17.       
  18.       private var _resourceParams:Array;
  19.       
  20.       private var _bundleName:String;
  21.       
  22.       private var _useHTML:Boolean = false;
  23.       
  24.       private var cachedEmbeddedFont:Font;
  25.       
  26.       public function LocalizedText()
  27.       {
  28.          super();
  29.          this.selectable = false;
  30.       }
  31.       
  32.       private function set _143661260resourceParams(param1:Array) : void
  33.       {
  34.          trace(this.id + " set resourceName: " + this.resourceName);
  35.          this._resourceParams = param1;
  36.          invalidateProperties();
  37.       }
  38.       
  39.       [Bindable(event="propertyChange")]
  40.       public function set resourceName(param1:String) : void
  41.       {
  42.          var _loc2_:Object = this.resourceName;
  43.          if(_loc2_ !== param1)
  44.          {
  45.             this._384566343resourceName = param1;
  46.             this.dispatchEvent(PropertyChangeEvent.createUpdateEvent(this,"resourceName",_loc2_,param1));
  47.          }
  48.       }
  49.       
  50.       override protected function commitProperties() : void
  51.       {
  52.          if(this.resourceName)
  53.          {
  54.             if(this.useHTML)
  55.             {
  56.                htmlText = this.localizeText();
  57.             }
  58.             else
  59.             {
  60.                text = this.localizeText();
  61.             }
  62.          }
  63.          super.commitProperties();
  64.       }
  65.       
  66.       private function set _384566343resourceName(param1:String) : void
  67.       {
  68.          this._resourceName = param1;
  69.          invalidateProperties();
  70.       }
  71.       
  72.       private function set _1377046061bundleName(param1:String) : void
  73.       {
  74.          this._bundleName = param1;
  75.          invalidateProperties();
  76.       }
  77.       
  78.       protected function localizeText() : String
  79.       {
  80.          return LocalizationManager.getInstance().getString(this.resourceName,this.bundleName,this.resourceParams);
  81.       }
  82.       
  83.       override public function initialize() : void
  84.       {
  85.          super.initialize();
  86.       }
  87.       
  88.       [Bindable(event="propertyChange")]
  89.       public function set bundleName(param1:String) : void
  90.       {
  91.          var _loc2_:Object = this.bundleName;
  92.          if(_loc2_ !== param1)
  93.          {
  94.             this._1377046061bundleName = param1;
  95.             this.dispatchEvent(PropertyChangeEvent.createUpdateEvent(this,"bundleName",_loc2_,param1));
  96.          }
  97.       }
  98.       
  99.       [Bindable(event="propertyChange")]
  100.       public function set useHTML(param1:Boolean) : void
  101.       {
  102.          var _loc2_:Object = this.useHTML;
  103.          if(_loc2_ !== param1)
  104.          {
  105.             this._148395598useHTML = param1;
  106.             this.dispatchEvent(PropertyChangeEvent.createUpdateEvent(this,"useHTML",_loc2_,param1));
  107.          }
  108.       }
  109.       
  110.       protected function ensureGlyphs(param1:String) : void
  111.       {
  112.          var _loc2_:String = null;
  113.          var _loc3_:Font = null;
  114.          if(!this.isFontRetrieved)
  115.          {
  116.             this.isFontRetrieved = true;
  117.             _loc2_ = getStyle("fontFamily");
  118.             if(_loc2_.match(/,/))
  119.             {
  120.                return;
  121.             }
  122.             for each(_loc3_ in fontArray)
  123.             {
  124.                if(_loc3_.fontName == _loc2_)
  125.                {
  126.                   this.cachedEmbeddedFont = _loc3_;
  127.                   this.defaultAppFontFamily = StyleManager.getStyleDeclaration("Application").getStyle("fontFamily");
  128.                }
  129.             }
  130.          }
  131.          if(this.cachedEmbeddedFont)
  132.          {
  133.             if(!this.cachedEmbeddedFont.hasGlyphs(param1))
  134.             {
  135.                setStyle("fontFamily",this.defaultAppFontFamily);
  136.             }
  137.             else
  138.             {
  139.                setStyle("fontFamily",this.cachedEmbeddedFont.fontName);
  140.             }
  141.          }
  142.       }
  143.       
  144.       [Bindable(event="propertyChange")]
  145.       public function set resourceParams(param1:Array) : void
  146.       {
  147.          var _loc2_:Object = this.resourceParams;
  148.          if(_loc2_ !== param1)
  149.          {
  150.             this._143661260resourceParams = param1;
  151.             this.dispatchEvent(PropertyChangeEvent.createUpdateEvent(this,"resourceParams",_loc2_,param1));
  152.          }
  153.       }
  154.       
  155.       private function set _148395598useHTML(param1:Boolean) : void
  156.       {
  157.          this._useHTML = param1;
  158.          invalidateProperties();
  159.       }
  160.       
  161.       public function get useHTML() : Boolean
  162.       {
  163.          return this._useHTML;
  164.       }
  165.       
  166.       public function get resourceParams() : Array
  167.       {
  168.          return this._resourceParams;
  169.       }
  170.       
  171.       public function get resourceName() : String
  172.       {
  173.          return this._resourceName;
  174.       }
  175.       
  176.       public function get bundleName() : String
  177.       {
  178.          return this._bundleName;
  179.       }
  180.    }
  181. }
  182.  
  183.